package com.example.zhu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.zhu.entity.AddressBook;
import com.example.zhu.entity.UserMoney;
import com.example.zhu.entity.Users;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UsersMapper extends BaseMapper<Users> {


    @Select("select * from user_money where openid = #{openid}")
    UserMoney selectMoney(String openid);

    @Update("update user_money set paopao_coins = #{paopaoCoins},money=#{money} where openid = #{openid}")
    void update(Integer paopaoCoins, Integer money, String openid);

    @Delete("delete from users where id = #{id}")
    void deleteByUserId(Integer id);

    @Select("select * from users where openid = #{openid}")
    Users selectByOpenid(String openid);

    @Update("update users set type = #{type} where openid = #{openid}")
    void updateByOpenid(String openid, Integer type);

    @Select("select openid from users")
    List<String> selectAllOpenid();

    @Select("select t2.* from users t1,address_book t2 where t1.openid = t2.openid and t1.openid = #{openid} and t1.type = 1 and t2.is_default = 1")
    AddressBook selectByOpenidMax(String openid);
}
